package com.libl.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration//把该类标注为配置类，适合于创建第三方提供的对象

@EnableTransactionManagement
@EnableAspectJAutoProxy

@Import(value={JdbcConfig.class,MybatisConfig.class})//导入另外两个配置类
@ComponentScan(value={"com.libl.config","com.libl.service","com.libl.testAutowired"})//配置要开启注解扫描的包
public class SpringConfig {

    @Bean//替换xml中的创建事务管理器的bean标签，不指定名称时储存在IOC容器中对象的名字默认是方法名
    public DataSourceTransactionManager transactionManager(@Autowired DataSource dataSource){

        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(dataSource);

        return transactionManager;
    }
}
